using UnityEngine;
using UFrame.TableCfg;
using System;

public class TableAgent : AgentContext<TableAgent, TableCtrl>
{
    protected Action m_onLoadFinish;

    public static void StartLoad(Action callback)
    {
        Context.StartLoadFromResource(callback);
    }
    public void StartLoadFromResource(Action callback)
    {
        m_onLoadFinish = callback;
        Instance.SetLoader(new ResourceTextLoader("Tables"));
        Instance.StartLoadAll(Context.OnLoadCallBack);
    }

    public void StartLoadFromStreaming(Action callback)
    {
        m_onLoadFinish = callback;
        var url = Application.streamingAssetsPath + "/Tables";
#if UNITY_EDITOR
        url = "file:///" + url;
#endif
        Instance.SetLoader(new UrlTextLoader(url));
        Instance.StartLoadAll(OnLoadCallBack);
    }

    private void OnLoadCallBack(int tableId, int countNow)
    {
        if (countNow == TableCtrl.TABLE_NUM)
        {
            if (m_onLoadFinish != null)
                m_onLoadFinish.Invoke();
        }
    }
}

